package retrofit.boot.client;

import lombok.extern.slf4j.Slf4j;
import retrofit.ErrorHandler;
import retrofit.RetrofitError;
import retrofit.boot.exception.*;

/**
 * Created by wulg on 2019/10/21
 * description:Retrofit-ErrorHandler实现类
 */
@Slf4j
public class RetrofitErrorHandler implements ErrorHandler {

    @Override
    public Throwable handleError(RetrofitError error) {
        switch (error.getKind()) {
            case NETWORK:
                return new RetrofitClientNetworkException(error.getCause());
            case CONVERSION:
                return new RetrofitClientConvertionException(error.getCause());
            case HTTP:
                return new RetrofitClientHttpException(error.getResponse(),error.getCause());
            case UNEXPECTED:
                return new RetrofitClientUnexpectedException(error.getCause());
            default:
                return new RetrofitClientUnexpectedException(error.getCause());
        }
    }
}
